thash_data_t *__alloc_chain(thash_cb_t *);
-static void cch_mem_init(thash_cb_t *hcb)
+static inline void cch_mem_init(thash_cb_t *hcb)
{
- int num;
- thash_data_t *p;
-
- hcb->cch_freelist = p = hcb->cch_buf;
- num = (hcb->cch_sz/sizeof(thash_data_t))-1;
- do{
- p->next =p+1;
- p++;
- num--;
- }while(num);
- p->next = NULL;
+ hcb->cch_free_idx = 0;
+ hcb->cch_freelist = NULL;
}
static thash_data_t *cch_alloc(thash_cb_t *hcb)
thash_data_t *p;
if ( (p = hcb->cch_freelist) != NULL ) {
hcb->cch_freelist = p->next;
+ return p;
+ }
+ if (hcb->cch_free_idx < hcb->cch_sz/sizeof(thash_data_t)) {
+ p = &((thash_data_t *)hcb->cch_buf)[hcb->cch_free_idx++];
+ p->page_flags = 0;
+ p->itir = 0;
+ p->next = NULL;
+ return p;
}
- return p;
+ return NULL;
}
/*
void thash_init(thash_cb_t *hcb, u64 sz)
{
int num;
- thash_data_t *head, *p;
+ thash_data_t *head;
hcb->pta.val = (unsigned long)hcb->hash;
hcb->pta.vf = 1;
hcb->pta.ve = 1;
hcb->pta.size = sz;
- hcb->cch_rec_head = hcb->hash;
head=hcb->hash;
num = (hcb->hash_sz/sizeof(thash_data_t));
head++;
num--;
}while(num);
-
- hcb->cch_freelist = p = hcb->cch_buf;
- num = hcb->cch_sz / sizeof(thash_data_t);
- do{
- p->page_flags = 0;
- p->itir = 0;
- p->next =p+1;
- p++;
- num--;
- }while(num);
- (p - 1)->next = NULL;
+ hcb->cch_free_idx = 0;
+ hcb->cch_freelist = NULL;
}
u64 hash_sz; // size of above data.
void *cch_buf; // base address of collision chain.
u64 cch_sz; // size of above data.
+ u64 cch_free_idx; // index of free entry.
thash_data_t *cch_freelist;
- thash_data_t *cch_rec_head; // cch recycle header
PTA pta;
} thash_cb_t;